/*
 *    This file is part of SSHTunneler.
 *
 *    Copyright 2009 Jean-Sebastien Gelinas <calestar@gmail.com>
 *
 *    SSHTunneler is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    SSHTunneler is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with SSHTunneler.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package sshtunneler.installer;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class ShowLicense extends javax.swing.JDialog implements ActionListener {
	private static final long serialVersionUID = -3858042802035293667L;
	private JScrollPane jScrollPane;
	private JTextArea text;
	private JButton cmd_accept;
	private JButton cmd_deny;
	private JPanel panel_cmd;

	private boolean accepted = false;

	public ShowLicense(String license) {
		this.setModal(true);
		this.setTitle("Licensing information ...");
		this.setLayout(new BorderLayout());
		this.setPreferredSize(new Dimension(600, 400));
		this.setLocationByPlatform(true);

		this.jScrollPane = new JScrollPane();
		this.text = new JTextArea();
		this.cmd_accept = new JButton("Accept");
		this.cmd_deny = new JButton("Deny");
		this.panel_cmd = new JPanel();
		this.panel_cmd.setLayout(new BorderLayout());

		this.cmd_accept.addActionListener(this);
		this.cmd_deny.addActionListener(this);

		this.panel_cmd.add(this.cmd_accept, BorderLayout.EAST);
		this.panel_cmd.add(this.cmd_deny, BorderLayout.WEST);

		this.add(this.jScrollPane, BorderLayout.CENTER);
		this.add(this.panel_cmd, BorderLayout.SOUTH);

		this.jScrollPane.getViewport().add(this.text);
		this.pack();

		this.text.setEditable(false);
		this.text.setText(license);
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource().equals(this.cmd_accept)) {
			this.accepted = true;
		}
		this.setVisible(false);
	}

	public boolean isAccepted() {
		return this.accepted;
	}
}
